package com.hatricks.is;

//import com.hatricks.base.threadpool.MultiThreadTransaction;

import com.hatricks.is.redission.configuration.RedissonConfiguration;
import com.hatricks.is.websocket.WebSocketServer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.io.IOException;
import java.time.Duration;

/**
 * @packageName: com.hatricks
 * @className: SpringBootPublic
 * @author: yanyuhui yanyuhui@chinasofti.com
 * @date: 2022/6/8 9:36
 * @description:
 */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, MongoAutoConfiguration.class})
@MapperScan(basePackages = "com.hatricks.is.*.mapper")
@RestController
@ApiIgnore
public class BusinessApplication {
    public static void main(String[] args) {
        SpringApplication.run(BusinessApplication.class);
        //MultiThreadTransaction bean = context.getBean(MultiThreadTransaction.class);
        //bean.test();
    }

    @Resource
    private WebSocketServer webSocketServer;

    /**
     * 手机客户端请求接口
     */
    @PostMapping(value = "/onReceive")
    public void onReceive(String id, String pwd) throws IOException {
        webSocketServer.broadCastInfo(id);
    }


    @GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> streamData() {
        // 创建一个每3秒发出一个"aaa"的流
        return Flux.interval(Duration.ofSeconds(3)).map(sequence -> "aaa");
    }
}
